package integrated

import (
	"talent.com/agency_im/common/msg"
	"talent.com/agency_im/common/pay"
	"talent.com/agency_im/modules/core"
	"talent.com/server/durotar.git/log"
)

type AgencyTopicListener struct{}

func (ls *AgencyTopicListener) OnBeginConversation(sourceID uint64, targetID uint64) error {
	// 发送欢迎语
	var (
		greetings string
		err       error
		message   *msg.Message
	)
	greetings, err = pay.GetAgencyGreeting(sourceID, targetID)
	if err != nil {
		log.Error("Get greetings on begin topic fail, error : %v", err)
		return err
	} else if greetings == "" {
		log.Debug("Get no greetings, use default, from %v to %v", sourceID, targetID)
		return nil
	}

	message = &msg.Message{
		TopicType: int8(msg.TOPIC_TYPE_PRIVATE),
		SourceID:  targetID,
		TargetID:  sourceID,
		MsgType:   int8(msg.MSG_TYPE_TEXT),
		SendSelf:  false,
		Info:      greetings,
	}
	err = core.SendMessage(message)
	if err != nil {
		log.Error("Send greeting message fail, user enter topic from [%v] to [%v]", sourceID, targetID)
	}
	return nil
}
